﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Entities;
using Unity.Transforms;
using Unity.Jobs;
using Unity.Burst;
using Unity.Collections;
using Unity.Mathematics;

/*public class MoveSystem : ComponentSystem
{
    protected override void OnUpdate()
    {
        Entities.ForEach(
            (ref Translation translation, ref SpeedComponent speedComp) =>
            {
                if (translation.Value.x > 20)
                    speedComp.Speed = -speedComp.Speed;
                if (translation.Value.x < -20)
                    speedComp.Speed = -speedComp.Speed;
                translation.Value.x += Time.DeltaTime * speedComp.Speed;
            }
        );
    }
}*/

public class MoveSystem : JobComponentSystem
{

    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        float dtime = Time.DeltaTime;
        JobHandle jbh = Entities.ForEach(
            (ref Translation translation, ref SpeedComponent speedComp) =>
            {
                if (translation.Value.x > 20)
                    speedComp.Speed = -speedComp.Speed;
                if (translation.Value.x < -20)
                    speedComp.Speed = -speedComp.Speed;
                translation.Value.x += dtime * speedComp.Speed;
            }
        ).Schedule(inputDeps);
        return jbh;
    }
}

